﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ChineseSchool.BLL;
using ChineseSchool.Models.Hethong;

namespace ChineseSchool.UserControl.ThuNghiem
{
    public partial class ActivitiesDetail : System.Web.UI.UserControl
    {
        private readonly B_Homework homeworkServices = new B_Homework();
        private readonly B_Lessons lessonService = new B_Lessons();
        private readonly B_Insert_Update_Delete crud = new B_Insert_Update_Delete();
        readonly B_User userService = new B_User();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            lblActivitiesDetail.Text = LoadActivitiesContent();
            //LoadUserInfo();
        }

        public string LoadActivitiesContent()
        {
            var strActivities = "";
            if (Request.QueryString["id"] != null && Request.QueryString["id"] != "")
            {
                var activitiesId = int.Parse(Request.QueryString["id"]);
                var activities = (new B_Activities()).GetByPK(activitiesId);
                if (activities != null)
                {
                    strActivities += "<h1><a href=\"#\">" + activities.ActivitiesTitle + "</a></h1>";
                    strActivities += "<div class=\"article-like-comment-date\">";
                    strActivities += "Posted by <a href=\"#author\">Author</a> " +
                                     "on <time datetime=\"" + activities.ActivitiesDate + "\">"
                                     + activities.ActivitiesDate + "</time> in <a href=\"#category\">Category</a>";
                    strActivities += "    <a class=\"like\" href=\"#\"><i class=\"fa fa-thumbs-o-up\"></i>08</a>";
                    strActivities += "    <a class=\"comments\" href=\"#\"><i class=\"fa fa-comments-o\"></i>49</a>";
                    strActivities += "</div>";

                    strActivities += " <p>" + activities.ActivitiesContent + "</p>";

                    strActivities += "<div class=\"article-tags\">";
                    strActivities +=
                        "    Tag: <a href=\"#tag1\">tieng trung</a>, <a href=\"#tag2\">hoc tieng trung</a>, <a href=\"#tag3\">luyen thi hsk</a>";
                    strActivities += "</div>";

                    Page.Title = "" + activities.ActivitiesTitle + "";
                    Page.MetaDescription = "" + activities.ActivitiesTitle + "";
                    Page.MetaKeywords = "" + activities.ActivitiesTitle + "";
                }
                else
                {
                    Page.Title = "Học tiếng trung hiệu quả";
                }
            }
            return strActivities;
        }

        //protected void BtnPostCommentClick(object sender, EventArgs e)
        //{
        //    var userName = txtUserName.Text;
        //    var email = txtEmail.Text;
        //    var content = txtContent.Text;

        //    if (string.IsNullOrEmpty(userName))
        //    {
        //        Response.Write("<script type='text/javascript'>alert('Vui lòng điền họ tên');</script>");
        //        return;
        //    }

        //    if (string.IsNullOrEmpty(email))
        //    {
        //        Response.Write("<script type='text/javascript'>alert('Vui lòng điền email');</script>");
        //        return;
        //    }

        //    if (string.IsNullOrEmpty(content))
        //    {
        //        Response.Write("<script type='text/javascript'>alert('Vui lòng điền ý kiến');</script>");
        //        return;
        //    }

        //    var userComment = new M_UserComment();

        //    userComment.ModuleId = 2;
        //    userComment.ModuleName = "1";
        //    userComment.UserName = userName;
        //    userComment.Email = email;
        //    userComment.PostContent = content;
        //    userComment.PostDate = DateTime.Now;

        //    crud.insert("UserComment", "PostId", userComment);
        //}

        //private void LoadUserInfo()
        //{
        //    string userName = Session["Username"].ToString();
        //    string userPassword = Session["PassWord"].ToString();
        //    var currentUser = userService.Selectby_username_password(userName, userPassword);

        //    if (currentUser != null)
        //    {
        //        txtUserName.Text = currentUser.UserName;
        //        txtEmail.Text = currentUser.Email;
        //    }
        //}
    }
}